package sfin.entity;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
/**
 * Original code from
 * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet165.java 
 */
public class TabFolder {
    
    public static void main (String [] args) {
        Display display = new Display ();
        Image image = new Image(display, 16, 16);
        GC gc = new GC(image);
        gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
        gc.fillRectangle(0, 0, 16, 16);
        gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
        gc.fillRectangle(3, 3, 10, 10);
        gc.dispose();
        final Shell shell = new Shell (display);
        shell.setLayout(new GridLayout());
        final CTabFolder folder = new CTabFolder(shell, SWT.BORDER);
        folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        folder.setSimple(false);
        folder.setUnselectedImageVisible(false);
        folder.setUnselectedCloseVisible(false);
        folder.setMinimizeVisible(false);
        folder.setMaximizeVisible(false);
        
        CTabItem item = new CTabItem(folder, SWT.CLOSE);
        item.setText("Item");
        item.setImage(image);
        
        final ScrolledComposite scrollComp = new ScrolledComposite(folder, SWT.V_SCROLL);
        item.setControl(scrollComp);
        
        final Composite tab1Comp = new Composite(scrollComp, SWT.NONE);
        tab1Comp.setLayout(new GridLayout(1,true));
        tab1Comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
        
        
        scrollComp.setContent(tab1Comp);
        scrollComp.setExpandVertical(true);
        scrollComp.setExpandHorizontal(true);
        scrollComp.addControlListener(new ControlAdapter() {
            public void controlResized(ControlEvent e) {
                Rectangle r = scrollComp.getClientArea();
                scrollComp.setMinSize(folder.computeSize(r.width, SWT.DEFAULT));
            }
        });
        Label text = new Label(tab1Comp,SWT.NONE);
        text.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
        text.setText("A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR");
        
        shell.setSize(300, 300);
        shell.open ();
        while (!shell.isDisposed ()) {
            if (!display.readAndDispatch ()) display.sleep ();
        }
        image.dispose();
        display.dispose ();
    }
}